import { EntityModel } from '@midwayjs/orm';
import { Column, JoinColumn, ManyToOne } from 'typeorm';
import { BaseModel } from '../utils/base.model';
import { ConvenientService } from './ConvenientService';
import { User } from './User';

export enum AttachmentType {
  FILE = 'file',
  TEXT = 'text',
}

@EntityModel()
export class Attachment extends BaseModel {
  @Column({ comment: '服务ID' })
  convenientId: number;

  @ManyToOne(() => ConvenientService, service => service.attachments)
  @JoinColumn()
  convenient: ConvenientService;

  @Column({
    comment: '附件类型',
    type: 'enum',
    enum: AttachmentType,
  })
  type: AttachmentType;

  @Column({
    comment: '字段名',
  })
  field: string;

  @Column({
    comment: '附件内容',
    nullable: true,
  })
  value: string;

  @ManyToOne(() => User)
  creator: User;
}
